package com.lys.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.lys.bo.AccountBO;
import com.lys.bo.AccountTransfor;
import com.lys.bo.ListBean;
import com.lys.dao.IAccountDAO;
import com.lys.po.Account;

@Service("accountService")
public class AccountService {

	private final List<AccountBO> accounts = null;
	
	@Autowired
	AccountTransfor accountTransfor;
	
	@Autowired
	private IAccountDAO accountDAO;

	public AccountService() {
		init();
	}

	private void init() {
	}

	/**
	 * @param accountDAO the accountDAO to set
	 */
	public void setAccountDAO(IAccountDAO accountDAO) {
		this.accountDAO = accountDAO;
	}

	/**
	 * @param accountTransfor the accountTransfor to set
	 */
	public void setAccountTransfor(AccountTransfor accountTransfor) {
		this.accountTransfor = accountTransfor;
	}

	public AccountBO getAccount(String userId) {
		List<Account> accounts = accountDAO.findByUserid(userId);
		if(!CollectionUtils.isEmpty(accounts)){
			Account account = accounts.get(0);
			return accountTransfor.toBO(account);
		}
		return null;

	}

	@SuppressWarnings("unchecked")
	public ListBean getAllAccounts() {
		List<Account> accounts = accountDAO.findAll();
		return new ListBean(accountTransfor.toBO(accounts));
	}
}
